package com.sgg.gulimall_search;


import com.sgg.gulimall_search.config.ElasticSearchConfig;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;


@SpringBootTest
public class test {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @Test
    public void test1() throws IOException {
//        RestHighLevelClient client = new RestHighLevelClient(
//                RestClient.builder(
//                        new HttpHost("1.15.98.26", 9200, "http")));
//

        IndexRequest request = new IndexRequest("posts");
        request.id("2");
        String jsonString = "{" +
                "\"user\":\"kimchy\"," +
                "\"postDate\":\"2013-01-30\"," +
                "\"message\":\"trying out Elasticsearch\"" +
                "}";
        request.source(jsonString, XContentType.JSON);
        IndexResponse index=
                restHighLevelClient.index(request, RequestOptions.DEFAULT);
        System.out.println("index-------------:"+ index);
    }


}
